package iunaldev.iunal;

import java.util.ArrayList;
import android.app.Activity;
import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.AdapterView;
import android.widget.ArrayAdapter;
import android.widget.ListView;
import android.widget.AdapterView.OnItemClickListener;

public class NivelNacional extends Activity{
	
	private ListView enlacesList;
	
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.nivel_nacional_activity);
		
		enlacesList = (ListView) findViewById(R.id.enlaceslistView);
		
		// Instanciating an array list (you don't need to do this, you already have yours)
        final ArrayList<String> arrayList = new ArrayList<String>();
        arrayList.add("http://www.observatorio.unal.edu.co/");
        arrayList.add("http://www.unal.edu.co/contenido/gobierno_nacional.htm");
        arrayList.add("http://www.unal.edu.co/csu/");
        arrayList.add("http://www.unal.edu.co/rector/");
        // This is the array adapter, it takes the context of the activity as a first // parameter, the type of list view as a second parameter and your array as a third parameter
        ArrayAdapter<String> arrayAdapter =      
        new ArrayAdapter<String>(this,android.R.layout.simple_list_item_1, arrayList);
        enlacesList.setAdapter(arrayAdapter); 
        
        //ListView listener
        enlacesList.setOnItemClickListener(new OnItemClickListener() {

			@Override
			public void onItemClick(AdapterView<?> a, View v, int position,	long id) {

				String uri = arrayList.get(position);
				Log.i(INPUT_SERVICE, "Pos: "+position);
				lanzarURI(uri);
			}
		});
	}
	
	public void lanzarURI(String url){
		Intent intent = new Intent(Intent.ACTION_VIEW);
		intent.setData(Uri.parse(url));
		startActivity(intent);
	}

}
